" vim:ft=vim

" Test new()
"
Before;
let X = object#class('X')

Execute(New cls can be instantiated with new() with default __init__ and __repr__);
let x = object#new(X)
Assert x.__class__ is# X
AssertEqual object#repr(x), "<X object>"

Execute(Hook into __init__ and __repr__);
function! X.__init__(name, size)
  let name = maktaba#ensure#IsString(a:name)
  let size = maktaba#ensure#IsNumber(a:size)
  let self.name = name
  let self.size = size
endfunction

function! X.__repr__()
  return printf('X(name=%s, size=%d)', self.name, self.size)
endfunction

let x = object#new(X, 'var', 4)
AssertEqual x.name, 'var'
AssertEqual x.size, 4
Assert object#repr(x) is# 'X(name=var, size=4)'

AssertThrows call object#new(g:X, 1, 4)
Assert g:vader_exception =~# 'WrongType'

Execute(Throws TypeError if arg0 is not a class);
AssertThrows call object#new(1)
Assert g:vader_exception =~# 'TypeError'
